
import React from 'react';
import PropTypes from 'prop-types';
import {injectIntl} from './intl';
import {Card, Row, Col, Table} from 'antd';
import {conventEnumValueToString, formatAmount} from '../utils';
import {partDeliveryType, currency, transportType} from '../Enum';
import DescriptionList from 'ant-design-pro/lib/DescriptionList';
import {TABLE} from '../constants';
const {Description} = DescriptionList;
import styles from './style.css';
/* eslint-disable react/prefer-stateless-function */
class Detail extends React.PureComponent {
    render() {
        const {details = []} = this.props.detail;
        const columns = [
            {
                title: this.props.intl.formatMessage({
                    id: 'commonDetail.column.partCode',
                    defaultMessage: '备件编号'
                }),
                dataIndex: 'partCode',
            },
            {
                title: this.props.intl.formatMessage({
                    id: 'commonDetail.column.partName',
                    defaultMessage: '备件名称'
                }),
                dataIndex: 'partName',
            },
            {
                title: this.props.intl.formatMessage({
                    id: 'commonDetail.column.partDescription',
                    defaultMessage: '备件描述'
                }),
                dataIndex: 'partDescription',
            },
            {
                title: this.props.intl.formatMessage({
                    id: 'commonDetail.column.oldPartCode',
                    defaultMessage: '被替换备件编号'
                }),
                dataIndex: 'oldPartCode',
            },
            {
                title: this.props.intl.formatMessage({
                    id: 'commonDetail.column.oldPartName',
                    defaultMessage: '被替换备件名称'
                }),
                dataIndex: 'oldPartName',
            },
            {
                title: this.props.intl.formatMessage({
                    id: 'commonDetail.column.deliveryQuantity',
                    defaultMessage: '交货数量'
                }),
                dataIndex: 'deliveryQuantity',
            },
            {
                title: this.props.intl.formatMessage({
                    id: 'commonDetail.column.price',
                    defaultMessage: '单价'
                }),
                dataIndex: 'price',
                className: styles.textAlign,
                render: text => formatAmount(text)
            },
            {
                title: this.props.intl.formatMessage({
                    id: 'commonDetail.column.totalAmount',
                    defaultMessage: '金额'
                }),
                dataIndex: 'totalAmount',
                className: styles.textAlign,
                render: text => formatAmount(text)
            }
        ];
        return (
            <div>
                <Card>
                    <DescriptionList size="large" title={<Row><Col span={6}>{this.props.intl.formatMessage({
                        id: 'commonDetail.order.title',
                        defaultMessage: '交货单信息'
                    })}</Col>
                    <Col className={styles.optionBtn} span={18}>{this.props.operations}</Col></Row>}>
                        <Description
                            term={this.props.intl.formatMessage({
                                id: 'commonDetail.info.sapDeliveryCode',
                                defaultMessage: '交货单号'
                            })}>
                            {this.props.detail.sapDeliveryCode}
                        </Description>
                        <Description
                            term={this.props.intl.formatMessage({
                                id: 'commonDetail.info.dealerCode',
                                defaultMessage: '总代编号'
                            })}>
                            {this.props.detail.dealerCode}
                        </Description>
                        <Description
                            term={this.props.intl.formatMessage({
                                id: 'commonDetail.info.sapTransferOrderCode',
                                defaultMessage: '调拨单号'
                            })}>
                            {this.props.detail.sapTransferOrderCode}
                        </Description>
                        <Description
                            term={this.props.intl.formatMessage({
                                id: 'commonDetail.info.partSaleOrderCode',
                                defaultMessage: '备件订单号'
                            })}>
                            {this.props.detail.partSaleOrderCode}
                        </Description>
                        <Description
                            term={this.props.intl.formatMessage({
                                id: 'commonDetail.info.status',
                                defaultMessage: '状态'
                            })}>
                            {conventEnumValueToString(partDeliveryType, this.props.detail.status)}
                        </Description>
                        <Description
                            term={this.props.intl.formatMessage({
                                id: 'commonDetail.info.currency',
                                defaultMessage: '币种'
                            })}>
                            {conventEnumValueToString(currency, this.props.detail.currency)}
                        </Description>
                        <Description
                            term={this.props.intl.formatMessage({
                                id: 'commonDetail.info.transportType',
                                defaultMessage: '运输方式'
                            })}>
                            {conventEnumValueToString(transportType, this.props.detail.transportType)}
                        </Description>
                    </DescriptionList>
                    <DescriptionList col={1} className={styles.mgtp} size="large">
                        <Description term={this.props.intl.formatMessage({
                            id: 'commonDetail.info.remark',
                            defaultMessage: '备注'
                        })}>
                            {this.props.detail.remark}
                        </Description>
                    </DescriptionList>
                </Card>
                <Card
                    title={this.props.intl.formatMessage({
                        id: 'commonDetail.details.title',
                        defaultMessage: '交货单清单'
                    })}
                    bordered={false}>
                    <Table className="white-space-nowrap" rowKey="id" columns={columns} pagination={false} dataSource={details} {...TABLE} />
                </Card>
            </div>
        );
    }
}

Detail.defaultProps = {
    detail: {},
};

Detail.propTypes = {
    detail: PropTypes.object,
    intl: PropTypes.object,
    isDetail: PropTypes.bool,
    operations: PropTypes.any,
};
export default injectIntl(Detail);
